package cn.tedu.store.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.tedu.store.bean.CartVo;
import cn.tedu.store.bean.Order;
import cn.tedu.store.bean.OrderItem;
import cn.tedu.store.bean.OrderItemVo;
import cn.tedu.store.mapper.OrderMapper;
@Service
public class OrderService implements IOrderService {
	@Resource
	private OrderMapper orderMapper;
	public Integer addOrder(Integer userid, List<CartVo> listCartVo) {
		Order order=new Order();
		order.setUserid(userid);
		orderMapper.insertOrder(order);
		for(CartVo c:listCartVo){
			OrderItem orderItem=new OrderItem();
			orderItem.setGoodsid(c.getGoodsid());
			orderItem.setCount(c.getCount());
			orderItem.setImage(c.getImage());
			orderItem.setUserid(userid);
			orderItem.setTitle(c.getTitle());
			orderItem.setPrice(c.getPrice());
			orderItem.setOrderid(order.getId());
			orderMapper.insertOrderItem(orderItem);
			
		}
		return order.getId();
	}
	/**
	 * 修改付款状态
	 * @param orderid
	 */
	public void updateStatus(Integer orderid) {
		orderMapper.updateStatus(orderid);
		
	}
	/**
	 * 查询用户的所有订单
	 */
	public List<OrderItemVo> getOrderItems(Integer userid) {
		
		return orderMapper.getOrderItems(userid);
	}

}
